﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SmallERP.Bll.PrintManage;
using SmallERP.MODEL.FoundationModel;
using Smallerp.Contracts;

namespace SmallERP.PrintManage
{
    public partial class FrmSelectPrinter : Form
    {
        private PrinterBLL _bll;

        public FrmSelectPrinter(IOperateDB inOp)
        {
            InitializeComponent();
            _OperateDb = inOp;
            _bll = new PrinterBLL(_OperateDb);
        }
        IOperateDB _OperateDb;
        private void FrmSelectPrinter_Load(object sender, EventArgs e)
        {
            try
            {
                LinkPrinter();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Environment.Exit(-1);
            }

        }
       
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (lkpPrinters.Text == "请选择打印机")
            {
                MessageBox.Show("请选择打印机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            ((FrmMain)this.Owner).Printer = _bll.GetPrinter(lkpPrinters.Text);
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Environment.Exit(-1);
        }

        private void LinkPrinter()
        {
            lkpPrinters.Properties.DataSource = _bll.GetPrinterList();
            lkpPrinters.Properties.DisplayMember = "PName";
        }
    }
}
